<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #box{
            width: 400px;
            height: 400px;
            margin: 80px auto;
        }
        #bbox{
            width: 300px;
            height: 300px;
            border: 1px solid #ccc;
        }

    </style>
</head>
<body>
    <div id="box">
        <div id="bbox"></div>
        <input type="submit" value="变色" id="btn">
    </div>
</body>
<script src="./public.js"></script>
<script>
    function createZero(n){
    if(n.length < 2){
        return "0" + n
    }
    return n;
}
    function Randomcolor(){
        var r = randomNum(0,255).toString(16);
        var g = randomNum(0,255).toString(16);
        var b = randomNum(0,255).toString(16);
        return '#' + createZero(r) + createZero(g) + createZero(b);
    }
    // console.log(Randomcolor());
    // bbox.style.background = (Randomcolor());
    
    btn.onclick = function(){
        randomNum(bbox.style.background = Randomcolor());
    }
</script>
</html>